package com.erdos.message.vo;

import java.io.Serializable;
import java.text.DateFormat;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.commons.lang.builder.ToStringBuilder;


/**
 * this is a message header definition for APS
 * @version $Id$
 * @author hcf
 * @since 2011-10-15
 */
public class APSMessageHeader implements Serializable {

	private static final long serialVersionUID = 8406544959832502781L;

	private String messageTypeId;
	
	private String messageId;

	private String correlationMessageTypeId;

	private String correlationMessageId;

	private String sender;
	
	private String receiver;
	
	private String sendDate;
	private String sendTime;
	private Integer length;
	public String getMessageTypeId() {
		return messageTypeId;
	}
	public void setMessageTypeId(String messageTypeId) {
		this.messageTypeId = messageTypeId;
	}
	public String getMessageId() {
		return messageId;
	}
	public void setMessageId(String messageId) {
		this.messageId = messageId;
	}
	public String getCorrelationMessageTypeId() {
		return correlationMessageTypeId;
	}
	public void setCorrelationMessageTypeId(String correlationMessageTypeId) {
		this.correlationMessageTypeId = correlationMessageTypeId;
	}
	public String getCorrelationMessageId() {
		return correlationMessageId;
	}
	public void setCorrelationMessageId(String correlationMessageId) {
		this.correlationMessageId = correlationMessageId;
	}
	public String getSender() {
		return sender;
	}
	public void setSender(String sender) {
		this.sender = sender;
	}
	public String getReceiver() {
		return receiver;
	}
	public void setReceiver(String receiver) {
		this.receiver = receiver;
	}
	public String getSendDate() {
		return sendDate;
	}
	public void setSendDate(String sendDate) {
		this.sendDate = sendDate;
	}
	public String getSendTime() {
		return sendTime;
	}
	public void setSendTime(String sendTime) {
		this.sendTime = sendTime;
	}
	public Integer getLength() {
		return length;
	}
	public void setLength(Integer length) {
		this.length = length;
	}
	
//	public Date getSendDateTime() {
//		if (this.getSendTime() == null
//				|| this.getSendTime().trim().length() == 0) {
//			return new Date();
//		}
//
//		DateFormat formatter = new SimpleDateFormat(L2Messaging.DATE_PATTERN);
//		return formatter.parse(this.getSendTime(), new ParsePosition(0));
//	}
	
	public Date getSendDateTime() {		
		String date=this.getSendDate();		
		String time=this.getSendTime();
		if(date==null || date.trim().length()==0) {			
			return new Date();
		} else {
			if(time==null || time.trim().length()==0) {
				time="000000";
			}
		}
		
		DateFormat formatter = new SimpleDateFormat(L2Messaging.DATE_PATTERN);
		
		return formatter.parse(date + time, new ParsePosition(0));
	}
	
	public String toString() {
		return new ToStringBuilder(this).append(this.messageTypeId).append(this.messageId)
			.append(this.correlationMessageTypeId).append(this.correlationMessageId)
			.append(this.sender).append(this.receiver).append(this.sendDate).append(this.sendTime)
			.toString();
	}
}
